home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pasclern.zip / DYNREC.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-01  |  2KB  |  74 lines

  1. PROGRAM a_dynamic_storage_record;
  2.  
  3. CONST  number_of_friends = 50;
  4.  
  5. TYPE full_name = RECORD
  6.       first_name : STRING[12];
  7.       initial    : CHAR;
  8.       last_name  : STRING[15];
  9.       END;
  10.  
  11.      date      = RECORD
  12.       day        : BYTE;
  13.       month      : BYTE;
  14.       year       : INTEGER;
  15.       END;
  16.  
  17.      person_id = ^person;
  18.      person    = RECORD
  19.       name       : full_name;
  20.       city       : STRING[15];
  21.       state      : STRING[2];
  22.       zipcode    : STRING[5];
  23.       birthday   : date;
  24.       END;
  25.  
  26. VAR   friend             : ARRAY[1..number_of_friends] OF person_id;
  27.       self,mother,father : person_id;
  28.       temp               : person;
  29.       index              : BYTE;
  30.  
  31. BEGIN  (* main program *)
  32.   new(self);   (* create the dynamic variable *)
  33.   self^.name.first_name := 'Charley';
  34.   self^.name.initial    := 'Z';
  35.   self^.name.last_name  := 'Brown';
  36.   WITH self^ DO
  37.   BEGIN
  38.     city := 'Anywhere';
  39.     state := 'CA';
  40.     zipcode := '97342';
  41.     birthday.day := 17;
  42.     WITH birthday DO
  43.     BEGIN
  44.       month := 7;
  45.       year := 1938;
  46.     END;
  47.   END;    (* all data for self now defined *)
  48.  
  49.   new(mother);
  50.   mother := self;
  51.   new(father);
  52.   father^ := mother^;
  53.   FOR index := 1 to number_of_friends DO
  54.   BEGIN
  55.     new(friend[index]);
  56.     friend[index]^ := mother^;
  57.   END;
  58.  
  59.   temp := friend[27]^;
  60.   WRITE(temp.name.first_name,' ');
  61.   temp := friend[33]^;
  62.   WRITE(temp.name.initial,' ');
  63.   temp := father^;
  64.   WRITE(temp.name.last_name);
  65.   WRITELN;
  66.  
  67.   dispose(self);
  68. { dispose(mother); } (* since mother is lost, it cannot
  69.                         be disposed of                  *)
  70.   dispose(father);
  71.   FOR index := 1 TO number_of_friends DO
  72.     dispose(friend[index]);
  73.  
  74. END. (* of main program *)